<?php
/**
 * Created by PhpStorm.
 * User: Dinh Thi
 * Date: 3/7/15
 * Time: 9:03 PM
 */

namespace MyApp\Application\Controller;


use MyApp\Application\Model\DaiLyModel;
use DinhThi\MVC\Request;
class DaiLyController extends MyAppAbstractController{
    public function __construct(){
        parent::__construct();
        parent::mustBeLogin();
    }

    public function TaoMoiAction(){
        if (isset($_POST['daily'])) {
            $daily  = $_POST['daily'];
            $sdt    = $_POST['sodienthoai'];
            $diachi = $_POST['diachi'];
            $model  = new DaiLyModel();
            echo json_encode($model->TaoDaiLy($daily, $diachi, $sdt));
        }
    }

    public function DanhSachAction(){
        $model = new DaiLyModel();
        echo json_encode($model->DanhSachDaiLy());
    }

    public function GiaoDichAction() {
        if (isset($_POST['daily'])) {
            $daily  = $_POST['daily'];
            $sotien = $_POST['sotien'];
            $ghichu = $_POST['ghichu'];
            $model  = new DaiLyModel();
            echo json_encode($model->QuyetToanCongNo($daily, $sotien, $ghichu));
        }
    }

    public function DanhSachGiaoDichAction() {
        $request = Request::getInstance();
        $params = $request->getParams();
        if (isset($params[2])) {
            $id = $params[2];
            $model = new DaiLyModel();
            echo json_encode($model->ChiTietGiaoDich($id));
        }
    }
} 